#include "klog.h"
#include <QDebug>

bool KLog::openLog = false;


#include <QtDebug>
#include <QFile>
#include <QTextStream>
#include "qt_knx.h"

void customMessageHandler(QtMsgType type, const char *msg)
{
        QString txt;
        switch (type) {
        //调试信息提示
        case QtDebugMsg:
                txt = QString("Debug: %1").arg(msg);
                break;

        //一般的warning提示
        case QtWarningMsg:
                txt = QString("Warning: %1").arg(msg);
        break;
        //严重错误提示
        case QtCriticalMsg:
                txt = QString("Critical: %1").arg(msg);
        break;
        //致命错误提示
        case QtFatalMsg:
                txt = QString("Fatal: %1").arg(msg);
                abort();
        }

        QFile outFile("debuglog.txt");
        outFile.open(QIODevice::WriteOnly | QIODevice::Append);
        QTextStream ts(&outFile);
        ts << txt << endl;
}

KLog::KLog()
{
}

void KLog::setLogOnOff(bool on)
{
    openLog = on;
}

void KLog::log(QString module_name, const char *msg, ...)
{
    if(openLog)
    {

    }
}


//void print_data(char *title, void *src, int len)
//{
//    _u8 *data = (_u8 *)src;
//    _int32 n = 1;
//    printf("\nDebug MEM: %s \n",title);
//    while (n<=len) {
//        printf(" %02x",*data);
//        if(n%8 == 0)
//            printf("\n");
//        data++;
//        n++;
//    }
//    printf("\n");
//}
